<script type="text/javascript">
$(document).ready(function() {
    var initial_width;
    //初始化完成
    $('#snapshot_policy_table').jqGrid({
        url: '/grid_snapshot_policy',
        styleUI: 'Bootstrap',
        datatype: 'json',
        mtype: 'POST',
        colNames: ['编号', '[["label name"|translate]]',
            "[['interval period'|translate]]", "[['interval unit'|translate]]",
            "[['label owner'|translate]]",
            '[["label Creation time"|translate]]', '[["label operation"|translate]]'
        ],
        colModel: [{
            name: 'id',
            index: 'id',
            width: 6,
            align: '',
            hidden: true
        }, {
            name: 'name',
            index: 'name',
            width: 8,
            align: 'left',
            formatter: function(cellvalue, option, row) {
                return '<a href="#" onclick="detail_open(\'' + option.gid + '\',\'' + option.rowId + '\')">' + cellvalue + '</a>';
            },
            unformat: function(cellvalue) {
                return cellvalue;
            }
        }, {
            name: 'count_show',
            index: 'count',
            width: 3,
            align: 'left'
        }, {
            name: 'unit_show',
            index: 'unit',
            width: 8,
            align: 'left',
            hidden: true
        }, {
            name: 'username',
            index: 'username',
            width: 4,
            align: 'left'
        }, {
            name: 'created_at',
            index: 'created_at',
            width: 4,
            align: 'left'
        }, {
            name: 'operation',
            index: 'operation',
            width: 3,
            align: 'left',
            sortable: false,
            detailHidden:true,
            formatter: function(cell, option, row) {
                var html = '';
                html += '<button style="margin-left:10px;" title="删除" class="btn btn-blue" onclick=confirm_snapshot_policy_delete(' + row[0] + ',"' + row[1] + '")>删除</button>';
                return html;
            }
        }],
        rowNum: 10,
        rowList: [10, 20, 30],
        sortname: 'id',
        sortorder: 'desc',
        viewrecords: true,
        altclass: 'ui-priority-secondary',
        altRows: true,
        autowidth: true,
        height: mainpanelHeight,
        shrinkToFit: true,
        beforeSelectRow:function(rowid, e) {
            if($(e.target).is('input')) {
                return true;
            }
            return false;
        },
        gridComplete: function() {
            var gridData = $(this).jqGrid('getRowData');
            jqgrid_page($(this), gridData);
            jqgrid_resize($(this));
        },
        resizeStart: function() {
            initial_width = $(this).width();
        },
        resizeStop: function() {
            return;
        }
    });
});

function snapshot_policy_delete(snapshot_id) {
    $.post("/snapshot_policy_delete", {
            'id': snapshot_id
        },
        function(data) {
            if (data.reply.is_success) {
                $('#snapshot_policy_table').trigger("reloadGrid");
                SelfAlert("删除成功", "完成提示");
            } else {
                error = data.reply.error;
                SelfAlert("删除失败：" + error)
            }
        });
}

function confirm_snapshot_policy_delete(snapshot_id, snapshot_name) {
    msg = '确认删除自动快照策略?';
    SelfConfirm(msg, snapshot_policy_delete, snapshot_id, "删除提示");
}

$("#auto_snapshot_policy").click(function() {
    angular.element('#auto_snapshot_policy').scope().open('/snapshot_policy_create');
});
</script>
<div class="panel panel-f-style">
    <div class="panel-body">
        <div class="title-tag">
            <h3>自动快照策略</h3>
            <p>自动快照策略管理</p>
        </div>
        <div class="grid-tools">
            <div class="grid-operate pull-left">
                <button class="btn btn-blue" type="button" id="auto_snapshot_policy" ng-controller="SnapshotModalCtrl">创建</button>
            </div>
        </div>
        <div class="grid-body" id="gridttt">
            <table id="snapshot_policy_table"></table>
        </div>
    </div>
</div>
<!-- <div class="panel panel-default">
        <div class="panel-body">
                <div class="item_toolsbar">
                    <input type="button" value="[['button create'|translate]]" class="button button_gray" id="auto_snapshot_policy"  ng-controller="SnapshotModalCtrl"/>&nbsp;
                    <span class="message_img">&nbsp;</span> 
                </div>
                <div id="div_snapshot_task_table" class='tab_warp'>
                    <table id="snapshot_policy_table"></table>
                </div>
        </div> panel-body
</div>
 -->
